//导入路由必须的两个方法
import { createRouter, createWebHistory } from 'vue-router'

//导入组件，即参与路由管理的两个页面Layout.vue，Login.vue
import LoginVue from '@/views/Login.vue'
import LayoutVue from '@/views/Layout.vue'


//导入子路由对应的页面即vue
import ArticleCategoryVue from '@/views/article/ArticleCategory.vue'
import ArticleManageVue from '@/views/article/ArticleManage.vue'
import UserAvatarVue from '@/views/user/UserAvatar.vue'
import UserInfoVue from '@/views/user/UserInfo.vue'
import UserResetPasswordVue from '@/views/user/UserResetPassword.vue'


//定义路由关系，path: '/login'访问/login就会显示LoginVue页面
                //path: '/'访问/就会显示LayoutVue页面，，，redirect表示重定向到/article/manage页面，这里就表示访问/时，会自动再次跳转到/article/manage路由，也就是登陆后默认先显示文章管理页面
const routes = [
    { path: '/login', component: LoginVue },
    {
        path: '/', component: LayoutVue,redirect:'/article/manage', children: [
            { path: '/article/category', component: ArticleCategoryVue },
            { path: '/article/manage', component: ArticleManageVue },
            { path: '/user/info', component: UserInfoVue },
            { path: '/user/avatar', component: UserAvatarVue },
            { path: '/user/resetPassword', component: UserResetPasswordVue }
        ]
     }
]

//创建路由器router，固定格式
const router = createRouter({
    history: createWebHistory(),
    routes: routes  //这是上面定义的路由关系
})

//导出路由器router
export default router
